package net.jbot.analyzer.impl;

import java.util.ListIterator;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;

import net.jbot.analyzer.AbstractAnalyzer;

public class NodeAnalyzer extends AbstractAnalyzer {

	@SuppressWarnings("unchecked")
	@Override
	protected boolean canRun(ClassNode node) {
		int ownType = 0, longType = 0;
		ListIterator<FieldNode> fnIt = node.fields.listIterator();
		while (fnIt.hasNext()) {
			FieldNode fn = fnIt.next();
			if ((fn.access & Opcodes.ACC_STATIC) == 0) {
				if (fn.desc.equals(String.format("L%s;", node.name)))
					ownType++;
				if (fn.desc.equals("J")) {
					longType++;
				}
			}
		}
		return ownType == 2 && longType == 1;
	}

	@Override
	protected void analyze(ClassNode node) {
		System.out.println("Node Class: " + node.name);
	}

}
